package com.example.studentvotesystem.mapper;

import com.example.studentvotesystem.entity.VoteRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface VoteRecordMapper {
    @Insert("INSERT INTO vote_record(user_id, spot_id) VALUES(#{userId}, #{spotId})")
    int insert(VoteRecord voteRecord);

    @Select("SELECT * FROM vote_record WHERE user_id = #{userId} AND spot_id = #{spotId}")
    VoteRecord selectByUserAndSpot(@Param("userId") Integer userId, @Param("spotId") Integer spotId);

    @Select("SELECT COUNT(*) FROM vote_record WHERE user_id = #{userId}")
    int countByUser(Integer userId);

    @Select("SELECT COUNT(*) FROM vote_record WHERE spot_id = #{spotId}")
    int countBySpot(Integer spotId);
}
